package com.lt.contract.service.impl;

import com.lt.contract.bean.NM_RENEW_CONTRACT;
import com.lt.contract.bean.utils.Constant;
import com.lt.contract.dao.NM_RENEW_CONTRACTMapper;
import com.lt.contract.service.NM_RENEW_CONTRACT_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class NM_RENEW_CONTRACT_ServiceImpl implements NM_RENEW_CONTRACT_Service {

    @Autowired
    NM_RENEW_CONTRACTMapper nm_renew_contractMapper;

    @Override
    public int deleteByPrimaryKey(NM_RENEW_CONTRACT record) throws Exception  {
        return nm_renew_contractMapper.deleteByPrimaryKey(record);
    }

    @Override
    public String insertSelective(NM_RENEW_CONTRACT record)  throws Exception {
        //判断续签合同中是否有重复业务编码
        if (nm_renew_contractMapper.getSerialNumberCount(record)>0){
            return Constant.serialNumberRepetition;
        }
        String code = String.valueOf(nm_renew_contractMapper.insertSelective(record));
        return code;
    }

    @Override
    public NM_RENEW_CONTRACT selectByPrimaryKey(String id) throws Exception {
        return nm_renew_contractMapper.selectByPrimaryKey(id);
    }

    @Override
    public String updateByPrimaryKeySelective(NM_RENEW_CONTRACT record) throws Exception {
        //1.先判断该数据是否修改过电路号码
        //2.如果没有直接修改
        //3.如果有再判断该电路号码是否已经存在于表中
        NM_RENEW_CONTRACT renew_contract =nm_renew_contractMapper.getUpdateSerialNumber(record);
        if (renew_contract.getSerialNumber()==null){
            return String.valueOf(nm_renew_contractMapper.updateByPrimaryKeySelective(record));
        }else if(renew_contract.getSerialNumber().equals(record.getSerialNumber())){
            return String.valueOf(nm_renew_contractMapper.updateByPrimaryKeySelective(record));
        }else if(nm_renew_contractMapper.getSerialNumberCount(record)>0){
            return Constant.serialNumberRepetition;
        }
        String code = String.valueOf(nm_renew_contractMapper.updateByPrimaryKeySelective(record));
        return code;
    }

    @Override
    public List<NM_RENEW_CONTRACT> queryRenewContractList(Map<String, Object> map) throws Exception {
        return nm_renew_contractMapper.queryRenewContractList(map);
    }

    @Override
    public Long getRenewContractListCount(Map<String, Object> map) throws Exception {
        return nm_renew_contractMapper.getRenewContractListCount(map);
    }
}
